//
//  DGAccountStore.h
//  DGAccountKit
//
//  Created by Jinxiao on 11/19/13.
//  Copyright (c) 2013 debugeek. All rights reserved.
//

@class DGAccount;

extern NSString * const DGAccountWillRemoveNotification;
extern NSString * const DGAccountDidRemoveNotification;

extern NSString * const DGAccountWillSaveNotification;
extern NSString * const DGAccountDidSaveNotification;

extern NSString * const DGAccountWillUpdateNotification;
extern NSString * const DGAccountDidUpdateNotification;

extern NSString * const DGCurrentAccountWillChangeNotification;
extern NSString * const DGCurrentAccountDidChangeNotification;

extern NSString * const DGAccountProfileWillUpdateNotification;
extern NSString * const DGAccountProfileDidUpdateNotification;

extern NSString * const DGAccountOldAccountKey;
extern NSString * const DGAccountNewAccountKey;
extern NSString * const DGAccountKey;
extern NSString * const DGAccountErrorKey;

typedef void (^DGAccountStoreOperationCompletion)(BOOL success, NSError *error);

typedef enum _DGAccountStoreUpdateOptions : NSInteger
{
    DGAccountStoreUpdateAccountCredential           = 1UL << 1,
} DGAccountStoreUpdateOptions;

@interface DGAccountStore : NSObject

+ (instancetype)sharedInstance;

@property (nonatomic, readonly, strong) NSArray *accounts;

- (void)loadAccountsFromLocal;

- (DGAccount *)accountByIdentifier:(NSString *)identifier;

- (BOOL)canSaveAccount:(DGAccount *)account error:(NSError **)error;

- (void)saveAccount:(DGAccount *)account options:(DGAccountStoreUpdateOptions)options completion:(DGAccountStoreOperationCompletion)completion;

- (void)updateAccount:(DGAccount *)account options:(DGAccountStoreUpdateOptions)options completion:(DGAccountStoreOperationCompletion)completion;

- (void)removeAccount:(DGAccount *)account options:(DGAccountStoreUpdateOptions)options completion:(DGAccountStoreOperationCompletion)completion;

@end